package com.fart.config;

import com.fart.common.JacksonObjectMapper;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.List;


/*
  web静态资源映射类
    classpath:/static/
    classpath:/public/
    classpath:/resources/
*/
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/backend/**")
                .addResourceLocations("classpath:/backend/");
    }
    /* mvc框架提供了 消息转换器 */
    @Override
    protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        //log.info("消息转换器..");

        //1.创建消息转换器的对象
        MappingJackson2HttpMessageConverter mc = new MappingJackson2HttpMessageConverter();
        //2.设置对象转换器,底层实现转换Jackson -> Object
        mc.setObjectMapper(new JacksonObjectMapper());
        //3.将自定义的类型转换 添加到开头的位置
        converters.add(0,mc);

    }
}
